package com.neusoft.elmboot.controller;

import com.neusoft.elmboot.po.Score;
import com.neusoft.elmboot.service.ScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/ScoreController")
public class ScoreController {

	@Autowired
	private ScoreService scoreService;

	@PostMapping("/listScoreByUserId")
	public List<Score> listScoreByUserId(@RequestParam String userId) {
		return scoreService.listScoreByUserId(userId);
	}

	@PostMapping("/getAllScore")
	public int getAllScore(@RequestParam String userId) {
		int totalScore = scoreService.getAllScore(userId);
		System.out.println("UserId: " + userId + ", Total Score: " + totalScore);
		return totalScore;
	}

	@PostMapping("/removeScore")
	public int removeScore(@RequestParam Integer scoreId) {
		return scoreService.removeScore(scoreId);
	}

	@PostMapping("/createScore")
	public int createScore(@RequestBody Score score) {
		return scoreService.createScore(score);
	}

	@PostMapping("/useScore")
	public int useScore(@RequestParam Integer orderId, @RequestParam Integer usedScore) {
		return scoreService.useScore(orderId, usedScore);
	}
}

